package com.dinadi.yidi.ui.activity;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.dinadi.yidi.R;
import com.dinadi.yidi.adapter.SettledCooperationViewPageAdapter;
import com.dinadi.yidi.base.BaseActivity;
import com.dinadi.yidi.ui.fragment.CoopertionFragment;
import com.dinadi.yidi.ui.fragment.SettledFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * author: JiaYu.He
 * Date: 2017/3/21  合伙入驻
 * Time: 15:11
 */

public class SettledCooperationActivtiy extends BaseActivity {

    private View view;
    private TextView tvTitle;
    private RadioGroup detail_radiogroup;
    private RadioButton ruzhu, hezuo;
    private ViewPager viewPager;
    private List<Fragment> mList = new ArrayList<>();

    @Override
    protected View getLayout() {
        view = LayoutInflater.from(SettledCooperationActivtiy.this).inflate(R.layout.activity_settled_cooperation, null);
        return view;
    }

    @Override
    protected void noWifiRefresh() {

    }

    @Override
    protected void initView() {
        changePager(2);
        tvTitle = (TextView) view.findViewById(R.id.text_title);
        tvTitle.setText(getResources().getString(R.string.text_cooperation));
        detail_radiogroup = (RadioGroup) view.findViewById(R.id.detail_radiogroup);
        viewPager = (ViewPager) view.findViewById(R.id.act_setled_vp);
        ruzhu = (RadioButton) view.findViewById(R.id.ruzhu);
        hezuo = (RadioButton) view.findViewById(R.id.hezuo);
        ruzhu.setSelected(true);
        detail_radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                //r入驻
                if (checkedId == R.id.ruzhu) {
                    ruzhu.setSelected(true);
                    hezuo.setSelected(false);
                    viewPager.setCurrentItem(0);

                }
                // 合伙
                if (checkedId == R.id.hezuo) {
                    ruzhu.setSelected(false);
                    hezuo.setSelected(true);
                    viewPager.setCurrentItem(1);
                }


            }

        });
    }

    @Override
    protected void initListener() {
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position == 0) {
                    hezuo.setSelected(false);
                    ruzhu.setSelected(true);
                } else {
                    ruzhu.setSelected(false);
                    hezuo.setSelected(true);
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected void initData() {
        mList.add(new SettledFragment()); //设计师入住
        mList.add(new CoopertionFragment()); //联系合作
        viewPager.setAdapter(new SettledCooperationViewPageAdapter(getSupportFragmentManager(), mList, this));
    }

    @Override
    protected void clickEvent(View v) {

    }

}
